package xyz.labmem.result

/**
 * @Author lty
 * @Date 2021/10/11 10:57
 */
open class ResultUtil {

    companion object {

        val SUCCESS_CODE = 0
        val FAILED_CODE = -1
        val FORM_FAILED_CODE = -2
        val LOGIN_FAILED_CODE = -3
        val SUCCESS_Message = "请求成功"
        val FAILED_Message = "请求失败"

        fun free(code: Int?, message: String?, data: Any?): ResultVo<Any> {
            return ResultVo(code, message, data)
        }

        fun success(data: Any?): ResultVo<*> {
            return free(SUCCESS_CODE, SUCCESS_Message, data)
        }

        fun success(data: Any?, message: String?): ResultVo<*> {
            return free(SUCCESS_CODE, message, data)
        }

        fun successMessage(message: String): ResultVo<*> {
            return success(null, message)
        }

        fun success(): ResultVo<*> {
            return success(null)
        }

        fun failed(message: String, data: Any?): ResultVo<*> {
            return free(FAILED_CODE, message, data)
        }

        fun failedMessage(message: String): ResultVo<*> {
            return failed(message, null)
        }

        fun userFailed(message: String): ResultVo<*> {
            return free(LOGIN_FAILED_CODE, message, null)
        }

        fun failed(data: Any?): ResultVo<*> {
            return failed(FAILED_Message, data)
        }

        fun failed(): ResultVo<*> {
            return failed(null)
        }

        //表单验证失败
        fun formFailed(message: String, data: Any): ResultVo<*> {
            return free(FORM_FAILED_CODE, message, data)
        }

        fun formFailed(): ResultVo<*> {
            return free(FORM_FAILED_CODE, "", null)
        }

        fun page(data: Any, count: Long): ResultPageVo<*> {
            return ResultPageVo(0, SUCCESS_Message, data, count)
        }
    }
}